﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Consulting : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ListAll();
        
        StringBuilder mylabel = new StringBuilder();
        if (Page.IsPostBack==false)
        {
            Application.Lock();

            for (int i = 15; i > 0; i--)
            {
                Application["A" + i] = (string)Application["A" + (i - 1)];
                mylabel.Append(Application["A" + (i - 1)]);
            
            }
            
            //加入問候語與提示
            Application["A1"] = (string)Session["nickname"] + "  " + DateTime.Now.ToLongTimeString() + "說 : <b>===大家好!===</b></br>";
            mylabel.Append(Application["A1"]);
            Label1.Text = mylabel.ToString();

            Application.UnLock();
        }

       
        if (Session["nickname"]!=null)
        {
            
        }

    }

    private void ListAll()
    {
        StringBuilder allchat = new StringBuilder();
        for (int i = 15; i > 0; i--)
        {
            allchat.Append((string)Application["A" + i]);
        }
        Label1.Text = allchat.ToString();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Application.Lock();

        StringBuilder mylabel = new StringBuilder();
        for (int i = 15; i > 0; i--)
        {
            Application["A" + i] = (string)Application["A" + (i - 1)];
            mylabel.Append(Application["A" + (i - 1)]);

        }
        Application["A1"] = (string)Session["nickname"] + "  " + DateTime.Now.ToLongTimeString() 
            + "說 : "+TextBox1.Text +"</br>";
        mylabel.Append(Application["A1"]);
        Label1.Text = mylabel.ToString();
        TextBox1.Text = "";

        Application.UnLock();
    }
}